home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte21 / ex5.c < prev    next >
C/C++ Source or Header  |  1995-05-29  |  3KB  |  56 lines

  1. #include <genstub.c>
  2.  
  3. #define LISTBOX_ID   1000
  4.  
  5. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  6. {
  7.    switch (uMsg)
  8.    {
  9.          case WM_CREATE:   // Create list box child window to show section keys.
  10.          {
  11.                RECT    rectClient;
  12.                LRESULT lRetVal = DefWindowProc(hWnd, uMsg, wParam, lParam);
  13.                GetClientRect( hWnd, &rectClient );       // Use client rectangle to center child.
  14.                CreateWindow( "listbox",                               // listbox class
  15.                              "child listbox",                         // name
  16.                              WS_CHILD | WS_VISIBLE | LBS_STANDARD,    // style
  17.                              10, 10,                                  // location
  18.                              rectClient.right - rectClient.left - 20, // width
  19.                              rectClient.bottom - rectClient.top - 20, // height
  20.                              hWnd,                                    // parent
  21.                              (HMENU) LISTBOX_ID,                      // child window ID
  22.                              hInst,                                   // app instance
  23.                              NULL );                                  // special parameters
  24.                return lRetVal;
  25.          }
  26.          case WM_COMMAND:
  27.                switch ( LOWORD( wParam ) )
  28.                {
  29.                      case IDM_TEST:
  30.                      {
  31.                            LPTSTR lpTemp = GetEnvironmentStrings( );
  32.                            HWND   hWndListBox = GetDlgItem( hWnd, LISTBOX_ID );
  33.                            if ( hWndListBox )
  34.                            {
  35.                               SendMessage( hWndListBox, LB_RESETCONTENT, 0, 0 );
  36.                               while ( *lpTemp )
  37.                               {
  38.                                  SendMessage( hWndListBox, LB_ADDSTRING, 0, (LPARAM) lpTemp );
  39.                                  lpTemp += lstrlen(lpTemp) + 1; // jump past null
  40.                               }
  41.                            }
  42.                      }
  43.                      break;
  44.                      case IDM_EXIT:
  45.                            DestroyWindow( hWnd );
  46.                            break;
  47.                }
  48.                break;
  49.          case WM_DESTROY:
  50.                PostQuitMessage( 0 );
  51.                break;
  52.          default:
  53.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  54.    }
  55.    return( NULL );
  56. }